#pragma once

#include <qcolor.h>
#include <qpushbutton.h>

#include <QComboBox>
#include <QDialog>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <QSpinBox>
#include <QWidget>
#include <array>
#include <qrcodegencpp/qrcodegen.hpp>
#include <utility>

#include "ColorPicker.hpp"

class ParamSetDialog : public QDialog
{
    Q_OBJECT

public:
    explicit ParamSetDialog(QWidget *parent = nullptr);

    QColor                 getFrontColor() const;
    QColor                 getBackColor() const;
    int                    getPixelSize() const;
    int                    getBorderSize() const;
    qrcodegen::QrCode::Ecc getEccLevel() const;

private slots:
    void onResetButtonClicked();
    void onCancleButtonClicked();
    void onAppluttonClicked();
    void onOKuttonClicked();

signals:
    void apply();

private:
    ColorPicker *frontColorPicker;  // 前景色选择器
    ColorPicker *backColorPicker;   // 背景色选择器
    QSpinBox    *pixelSizeSpinBox;  // 像素大小
    QSpinBox    *borderSizeSpinBox; // 边框大小
    QComboBox   *eccLevelComboBox;  // 纠错级别
    QPushButton *resetButton;       // 重置按钮
    QPushButton *cancelButton;      // 取消按钮
    QPushButton *applyButton;       // 应用按钮
    QPushButton *okButton;          // 确定按钮

    // 默认参数
    static inline const auto     defaultFrontColor      = Qt::black;
    static inline const auto     defaultBackColor       = Qt::white;
    static inline constexpr int  defaultPixelSize       = 6;
    static inline constexpr auto defaultPixelSizeRange  = std::make_pair(1, 100);
    static inline constexpr int  defaultBorderSize      = 3;
    static inline constexpr auto defaultBorderSizeRange = std::make_pair(1, 10);
    static inline constexpr int  defaultEccLevelIndex   = 1;

    using EccLevelPair = std::pair<const char *, qrcodegen::QrCode::Ecc>;

    static constexpr auto eccLevelPairs = std::to_array<EccLevelPair>(
        {
            {"Low (7%)", qrcodegen::QrCode::Ecc::LOW},
            {"Medium (15%)", qrcodegen::QrCode::Ecc::MEDIUM},
            {"Quartile (25%)", qrcodegen::QrCode::Ecc::QUARTILE},
            {"High (30%)", qrcodegen::QrCode::Ecc::HIGH},
        });

    QColor frontColor;    // 前景色
    QColor backColor;     // 背景色
    int    pixelSize;     // 像素大小
    int    borderSize;    // 边框大小
    int    eccLevelIndex; // 纠错级别索引

    void setupUI();
};
